<template>
  <div>
    <el-form
      :model="numberValidateForm"
      ref="numberValidateForm"
      label-width="100px"
      class="demo-form-inline"
      :rules="rules"
      :inline="true"
    >
      <el-form-item label="流量" prop="playTime">
        <el-input
          type="number"
          v-model="numberValidateForm.playTime"
          autocomplete="off"
          :disabled="!limitId"
        >
        </el-input>
      </el-form-item>
      <el-form-item class="ml-10" v-if="limitId">
        <el-button type="primary" @click="submitForm('numberValidateForm')"
          >提交</el-button
        >
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { mapState } from "vuex";

export default {
  name: "videoTraffic",
  data() {
    return {
      numberValidateForm: {
        playTime: 0,
      },
      rules: {
        playTime: [{ required: true, message: "请输入", trigger: "blur" }],
      },
    };
  },
  props: {
    number: {
      type: String,
    },
  },
  computed: {
    ...mapState(["siteInfos"]),
    limitId() {
      return this.siteInfos.homeId == "001e7548-8735-4b31-b30b-c9361a62c102";
    },
  },
  created() {
    this.getData();
  },
  methods: {
    getData() {
      this.$get("/fireFightingIOT/device/getVideoPlayTime", {
        number: this.number,
      }).then((res) => {
        if (res.code == 0) {
          this.numberValidateForm.playTime = res.data.playTime;
        }
      });
    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$post("/fireFightingIOT/device/setVideoPlayTime", {
            ...this.numberValidateForm,
            number: this.number,
          }).then((res) => {
            if (res.code == 0) {
              this.$message.success("操作成功");
              this.$emit("success");
            } else {
              this.$message.error("操作失败");
            }
          }).catch(err=>{
            this.$message.error(err.msg);
          });
        } else {
          return false;
        }
      });
    },
  },
};
</script>

<style lang="less" scoped>
/deep/.el-input-group__append,
.el-input-group__prepend {
  background-color: initial !important;
  border: none !important;
  color: #fff !important;
}
/deep/.el-dialog__body {
  display: flex !important;
  justify-content: center !important;
  height: 10vh !important;
}
</style>
